//
//  UIImage+Whitespace.m
//  ITC_iOS
//
//  Created by Benz.L on 03/09/2018.
//  Copyright © 2018 Benz.L. All rights reserved.
//

#import "UIImage+Whitespace.h"

@implementation UIImage(Whitespace)

- (UIImage *)whiteSpace:(WhtespaceEdgeInsets)edgeInsets {
    return [self whiteSpace:edgeInsets color:UIColor.clearColor];
}
- (UIImage *)whiteSpace:(WhtespaceEdgeInsets)edgeInsets color:(UIColor *)color {
    CGRect rect = CGRectMake(edgeInsets.left, edgeInsets.top, self.size.width+edgeInsets.left+edgeInsets.right, self.size.height+edgeInsets.top+edgeInsets.bottom);
    UIGraphicsBeginImageContextWithOptions(rect.size, NO, self.scale);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [self drawInRect:(CGRect){edgeInsets.left, edgeInsets.top, self.size}];
    CGContextSetFillColorWithColor(context, color.CGColor);
    CGContextSetBlendMode(context, kCGBlendModeNormal);
    CGContextFillRect(context, rect);
    
    UIImage*newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

@end
